package com.hsck.order.kds.base.isnoam.view

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView


class HrSpacesItemDecoration( val hSpace: Int, private val vSpace: Int) :
    RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State,
    ) {
        val position = parent.getChildAdapterPosition(view)
        val itemCount = state.itemCount

        outRect.top = vSpace
        outRect.bottom = vSpace

        // 对第一个和最后一个 item 进行处理
        when (position) {
            0 -> {
                outRect.left = 0
                outRect.right = hSpace
            }

            itemCount - 1 -> {
                outRect.left = hSpace
                outRect.right = 0
            }

            else -> {
                outRect.left = hSpace
                outRect.right = hSpace
            }
        }
    }
}

//class HrSpacesItemDecoration(private val hSpace: Int, private val vSpace: Int) :
//    RecyclerView.ItemDecoration() {
//    override fun getItemOffsets(
//        outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State,
//    ) {
//        val position = parent.getChildAdapterPosition(view)
//        val itemCount = state.itemCount
//
//        outRect.top = vSpace
//        outRect.bottom = vSpace
//
//        // 左右间距处理
//        outRect.left = hSpace
//        outRect.right = if ((position + 1) % 4 == 0) 0 else hSpace // 最后一列不加右间距
//    }
//}

